import React from "react"

import  myjson from "../../assets/data.json"
import "../../styles/sty/nav_yhb.css"



class nav_yhb extends React.Component{
    constructor(params) {
        super( )

        this.state={
             list:[],
             credits:""
        }
        
    }

    componentDidMount(){
        this.setState({
             list:myjson.data.items,
             credits:myjson.data.items

        })
        console.log(this.credits)
    }
    add(gold){

         let  go=localStorage.getItem("token")
            console.log(gold)
        const jbi=parseInt(gold)
        
        console.log(jbi)

        if(go==""){
            alert("请先登录")
            this.props.history.push("/login")
            console.log(gold)
        }else if(go!=""&&jbi<100){
            alert("兑换成功")
            this.props.history.push("/")
        }else if( go!=""&&jbi>100 ){
            alert("抱歉！兑换失败")
        }
    }
    render(){
        let { list }=this.state
      
        return(
            <div id="yhb">
                
               <ul id="ul3"> <span id="span1"></span>
              {list.map(({ title,logo,tagText,credits,recommendText,id})=>{
                            return (
                                <li >
                                    <img src={logo}/>
                                    <b>{title}</b>
                                    <p>{tagText}</p>
                                    <i>{credits}</i>
                                    <p id="p2" onClick={this.add.bind(this,credits)}>{recommendText}</p>
                                    <p>{id}</p>
                                </li>
                            )
                        })}
               </ul>
            </div>
        )
    }

}


// console.log(myjson.data.items)

export default nav_yhb
